home *** CD-ROM | disk | FTP | other *** search
- // student.h
- #include <iostream.h>
- #include <string.h>
-
- class Student
- {
- public:
- Student()
- {
- cout << "constructing student no name\n";
- semesterHours = 0;
- gpa = 0.0;
- name[0] = '\0';
- }
- Student(char *pName)
- {
- cout << "constructing student " << pName << "\n";
- strncpy(name, pName, sizeof(name));
- name[sizeof(name) - 1] = '\0';
-
- semesterHours = 0;
- gpa = 0.0;
- }
- Student(char *pName, int xfrHours, float xfrGPA)
- {
- cout << "constructing student " << pName << "\n";
- strncpy(name, pName, sizeof(name));
- name[sizeof(name) - 1] = '\0';
- semesterHours = xfrHours;
- gpa = xfrGPA;
- }
-
- /*
- // the following constructor uses default values to
- // serve the function of all three constructors above
- Student(char *pName = "no name",
- int xfrHours = 0,
- float xfrGPA = 0.0)
- {
- cout << "constructing student " << pName << "\n";
- strncpy(name, pName, sizeof(name));
- name[sizeof(name) - 1] = æ\0Æ;
- semesterHours = xfrHours;
- gpa = xfrGPA;
- }
- */
-
- ~Student()
- {
- // whatever assets are returned here
- }
-
- //grade - return the current grade point average
- float grade()
- {
- return gpa;
- }
- //hours - return the number of semester hours
- int hours()
- {
- return semesterHours;
- }
-
- //addCourse - add another course to the studentÆs record
- float addCourse(int hours, float grade);
-
- //here we allow the grade to be changed
- float grade(float newGPA)
- {
- float oldGPA = gpa;
- //only if the new value is valid
- if (newGPA > 0 && newGPA <= 4.0)
-
- {
- gpa = newGPA;
- }
- return oldGPA;
- }
-
- //the following members are off-limits to others
- protected:
- char name[40];
- int semesterHours; //hours earned towards graduation
- float gpa; //grade point average
- };
-